home *** CD-ROM | disk | FTP | other *** search
- /* Inside Mac Vol.IV p.240 */
- #if 0
- typedef struct HFSDefaults{
- char sigWord[2]; /* signature word, default 'BD' */
- long abSize; /* allocation block size in bytes, defaut 0
- meaning (1+(VolSize in blocks/64K) *512 bytes */
- long clpSize; /* clump size in bytes, default 4*abSize */
- long nxFreeFN; /* next free file number, default 16 */
- long btClpSize; /* B*-tree clump size in bytes, default 0
- meaning (volsize in blocks)/128*512 bytes */
- short rsrv1,rsrv2,rsrv3; /* reserved */
- } HFSDefaults;
- #endif
-
- se si dà annulla, non espelle il disco
-
-
- /* bisognerebbe stampare i valori correnti, se è un disco Mac !!!!!!!! */
-
- /* challenges for disk hackers:
- create unusual formats by talking directly to the hardware disk interface
- use sectors 0&1 as extensions tree
- make the last two sectors of the disk available for files
- create a reduced Desktop file before the Finder creates it, so that the maximum
- size is reached even under System 6
- create a disk where (for example) sector 0 says "I'm an MS-DOS disk, but sectors 2 to
- 719 are occupied by a foreign partition", and sector 2 says "I'm a Mac disk, but
- sectors 720 to 1439 are bad and can't be used"
- reduce the size allocated to extension tree, catalog & desktop without losing
- the files currently in the disk
- */
-
- mcopy(dest, src, len)
- register char*dest,*src;
- register int len;
- {
- while (--len>=0) *dest++ = *src++;
- }
-
- fillmem(dest, ch, len)
- register char*dest;
- register char ch;
- register int len;
- {
- while (--len>=0) *dest++ = ch;
- }
-
- #define NULL 0L
-
- char buffer[512];
- short drive_number;
- short err_code;
- static Point aPoint={80,52};
- Cursor waitCursor;
-
-
- #define d_quit 1
- #define d_clump 2
- #define d_extents 3
- #define d_check 6
- #define d_diskinsertion -1
-
- /* Pascal string -> integer */
- int pstrtoi(str)
- Str255 str;
- {
- register int i=str[0];
- register unsigned char *p=&str[1];
- register unsigned int val=0;
-
- while(i>0 && *p==' ') p++,i--;
- while(i>0 && *p>='0' && *p <='9' ){
- val = val*10+ *p -'0';
- p++; i--;
- }
- return val;
- }
-
-
- Boolean is_not_initialized()
- {
- /* There is not a device driver call for this purpose, but that range of
- errors is typical for non-initialized disks */
- leggi_settore(0,buffer);
- if(err_code<=-66 && err_code>=-71){
- leggi_settore(2,buffer);
- if(err_code<=-66 && err_code>=-71) return true;
- }
- return false;
- }
-
-
- main()
- {
- short kind;
- Handle h;
- Rect r;
- short itemHit;
- DialogPtr myDialog;
- HFSDefaults my_defs;
- EventRecord myEvent;
- Boolean riguarda_me;
- Boolean force_init;
- short j;
-
- InitMacintosh();
- h = (Handle)GetCursor(watchCursor);
- waitCursor = **(CursHandle)h;
-
- myDialog = GetNewDialog (128,NULL,(char*)-1);
-
- for(;;){
- ShowWindow(myDialog);
- /* handle the dialog */
- itemHit=0;
- do{
- SystemTask();
- riguarda_me = GetNextEvent(everyEvent, &myEvent);
- if(riguarda_me && myEvent.what==diskEvt){
- itemHit=d_diskinsertion;
- drive_number=(short)(myEvent.message);
- }
- else if( IsDialogEvent(&myEvent)){
- if(DialogSelect(&myEvent,&myDialog,&j))
- if(j==d_check){
- GetDItem(myDialog,d_check,&kind,&h,&r);
- SetCtlValue((ControlHandle)h,!GetCtlValue(h));
- }
- else
- itemHit=j;
- }
- }
- while (itemHit != d_diskinsertion && itemHit != d_quit );
- if(itemHit==d_quit) ExitToShell();
-
- HideWindow(myDialog);
-
- GetDItem(myDialog,d_clump,&kind,&h,&r);
- GetIText(h,buffer);
- my_defs.clpSize=(long)pstrtoi(buffer)<<9;
-
- GetDItem(myDialog,d_extents,&kind,&h,&r);
- GetIText(h,buffer);
- my_defs.btClpSize=(long)pstrtoi(buffer)<<9;
-
- GetDItem(myDialog,d_check,&kind,&h,&r);
- force_init=!GetCtlValue(h);
-
- /*DisposDialog(myDialog);*/
-
- my_defs.sigWord[0]='B'; my_defs.sigWord[1]='D';
- my_defs.abSize=512;
- my_defs.nxFreeFN=1;
- my_defs.rsrv1=my_defs.rsrv2=my_defs.rsrv3=0;
-
- FmtDefaults=&my_defs;
-
- if( force_init || is_not_initialized() || *(int*) buffer== 0x4244 && ((*(int*)&buffer[10])&0x200))
- /* System 7 sets that flag if one or more bad sectors were found and
- marked as unusable */
- DIBadMount(aPoint, myEvent.message);
- else
- mac_ize_disk((short)myEvent.message);
-
- FmtDefaults=NULL;
- }
- }
-
- static Handle icon_handle;
- static Rect iconRect={10,16,42,48};
-
-
- static pascal Boolean icon_update (theDialog, theEvent,itemHit)
- /* update routine for the disk initialization dialog: we've tried to
- copy the standard disk initialization dialog used by DIBadMount
- */
- DialogPtr theDialog;
- EventRecord *theEvent;
- int *itemHit;
- {
- if(theEvent->what==updateEvt && (WindowPtr)theEvent->message==theDialog){
- GrafPtr savePort;
- short kind;
- Handle h;
-
- GetPort( &savePort );
- SetPort(theDialog);
- PlotIcon(&iconRect,icon_handle);
- SetPort(savePort);
- }
- return false;
- }
-
-
- mac_ize_disk(drive_number)
- short drive_number;
- {
- /* see Technical Notes 70 and 272 */
- cntrlParam ParamBlock;
- DialogPtr initDialog;
- short item;
- short kind;
- Handle h;
- Rect r;
- char*volname;
-
- ParamBlock.ioRefNum=-5; /*.SONY driver*/
- ParamBlock.ioVRefNum=drive_number;
- ParamBlock.csCode=21; /* Return Physical Drive Icon */
- icon_handle=NewHandle(128);
- if(PBControl(&ParamBlock,0) != noErr)
- fillmem(*icon_handle,0,128);
- else
- mcopy(*icon_handle, *((Ptr*)&ParamBlock.csParam[0]), 128);
-
- initDialog=GetNewDialog(132,NULL,-1L);
-
- leggi_settore(2,buffer);
- if( *(int*) buffer== 0xD2D7 || *(int*) buffer== 0x4244)
- volname=&buffer[36];
- else
- volname="\pUntitled";
- GetDItem(initDialog,5,&kind,&h,&r);
- SetIText(h,volname);
- ModalDialog(icon_update,&item);
-
- GetIText(h,&buffer);
-
- if(item!=2){
- return;
- }
- else{
- int *IPtr;
- GrafPtr savePort;
- UnmountVol(NULL,drive_number);
- GetPort( &savePort );
- SetPort(initDialog);
- for(item=1;item<=5;item++){
- GetDItem(initDialog,item,&kind,&h,&r);
- InsetRect(&r,-4,-4);
- EraseRect(&r);
- }
- SetCursor(&waitCursor);
- MoveTo(64,20);
- DrawString("\pCreating directory...");
- DIZero (drive_number,buffer);
- SetPort(savePort);
- SetCursor(&arrow);
- }
- DisposDialog(initDialog);
- DisposHandle(icon_handle);
- }
-
-
-
- #if 0
- main()
- {
- HFSDefaults my_defs;
- EventRecord myEvent;
- int riguarda_me,catalog_sect;
- static Point aPoint={80,112};
-
- static unsigned char desktop[]="\pDesktop",
- finder[]="\pFinder 1.0";
-
- printf("\f");
- my_defs.sigWord[0]='B'; my_defs.sigWord[1]='D';
- my_defs.abSize=512;
- my_defs.clpSize=1024;
- my_defs.nxFreeFN=1;
- my_defs.btClpSize=1024;
- my_defs.rsrv1=my_defs.rsrv2=my_defs.rsrv3=0;
-
- do{
- riguarda_me = GetNextEvent(everyEvent, &myEvent);
- }
- while(!riguarda_me||myEvent.what!=diskEvt);
-
- printf("vado!\n");
-
- FmtDefaults=&my_defs;
-
- DIBadMount(aPoint, myEvent.message);
-
- FmtDefaults=NULL;
- return;
-
- {int io,refnum;
- Handle h;
- long count;
- static IOParam pb;
- int drive_number =1;
- io=SetVol(NULL,drive_number);
- CreateResFile(desktop);
- refnum=OpenResFile(desktop);
-
- h=NewHandle( (Size) sizeof(finder) );
- mcopy(*h, finder, sizeof(finder) );
- AddResource(h,'STR ',0,"\p");
- /*UpdateResFile(refnum);*/
-
- CloseResFile(refnum);
-
-
-
- {
- FileParam fpb;
- fpb.ioFVersNum = 0;
- fpb.ioFDirIndex = 0;
- fpb.ioVRefNum=drive_number;
- fpb.ioNamePtr=desktop;
- io=PBGetFInfo(&fpb, 0);
- /*fpb.ioFlFndrInfo.fdFlags |= fInvisible;*/
- fpb.ioFlFndrInfo.fdType='FNDR';
- fpb.ioFlFndrInfo.fdCreator='ERIK';
- io=PBSetFInfo(&fpb, 0);
- }
-
- pb.ioVersNum = 0;
- pb.ioPermssn = fsWrPerm;
- pb.ioMisc = 0;
- pb.ioNamePtr=desktop;
- pb.ioVRefNum=drive_number;
-
- io=PBOpenRF(&pb, 0);
-
- count=1536;
- io=Allocate (refnum,&count);
- printf("Allocate=%d\n",io);
- FSClose(refnum);
-
- UnmountVol (NULL,drive_number);
- Eject(NULL,drive_number);
-
- }
- return;
-
- {int io,refnum;
- long count;
- static IOParam pb;
-
- io=Create(desktop, 1, 'ERIK', 'FNDR');
- printf("create=%d\n",io);
-
- io = FSOpen( desktop, 1, &refnum );
- printf("open=%d\n",io);
- count=1536;
- io=Allocate (refnum,&count);
- printf("Allocate=%d\n",io);
-
- pb.ioVersNum = 0;
- pb.ioPermssn = fsWrPerm;
- pb.ioMisc = 0;
- pb.ioNamePtr=(unsigned char*)desktop;
- pb.ioVRefNum=1;
-
- io=PBOpenRF(&pb, 0);
- printf("openRF=%d\n",io);
- count=sizeof(desktop);
- printf("size=%ld\n",count);
- io=FSWrite( refnum, &count, desktop );
- printf("write=%d\n",io);
- }
-
-
- UnmountVol (NULL,1);
- Eject(NULL,1);
- return;
-
- leggi_settore(2,buffer);
- catalog_sect= *((int*)&buffer[150]) +4+1;
- printf("cat=%d\n",catalog_sect);
- leggi_settore(catalog_sect,buffer);
-
- {int i=0;
- int ok=0;
- int desktop_start,old_desk_size;
- static char desk_name[]="\pDesktop";
-
- for(i=0;i<512 && ok<sizeof(desk_name);i++){
- if(buffer[i]==desk_name[ok])
- ok++;
- else
- ok=0;
- }
- printf("i=%d\n",i);
- if(buffer[i]!=2){
- printf("non ci siamo");
- return;
- }
- #define new_size 2
- /* attento: che ci siano problemi di allineamento? */
- desktop_start= *((int*)&buffer[i+86]) +4;
- old_desk_size= *((int*)&buffer[i+88]);
- printf("desk start=%d\n",desktop_start);
- *((long*)&buffer[i+40])=(long)(new_size*512); /* physical length */
- *((int*)&buffer[i+88])=new_size; /* size of extent */
- *((int*)&buffer[i+72])=2048; /* clump size */
- scrivi_settore(catalog_sect,buffer); /* il catalogo ora dice che il desktop è corto */
- leggi_settore(3,buffer);
-
- for(i=desktop_start+new_size-4;i<desktop_start+old_desk_size-4;i++)
- BitClr(buffer,(long)i);
- scrivi_settore(3,buffer); /* la mappa bit ora dice che i settori sono liberi */
-
- leggi_settore(2,buffer);
- *((int*)&buffer[34]) += old_desk_size-new_size; /* unused allocation blocks */
- scrivi_settore(2,buffer); /* registra anche questo */
- scrivi_settore(*((int*)&buffer[18])+4,buffer); /* e la copia lassù, quel campo
- dà il numero di settori nel disco - i primi 4 - quegli ultimi 2 */
-
- }
-
-
- }
- #endif
-
-
- InitMacintosh()
- {
- InitGraf(&thePort);
- InitFonts();
- FlushEvents( everyEvent, 0 );
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
- MaxApplZone();
- }
-
-
- leggi_settore(sect_n,buffer)
- int sect_n;
- char *buffer;
- {
- /* from Inside Macintosh page II/216 */
- #define _Read 0xA002
- asm{
- moveq #24,D0 /* #<ioQElsize/2>-1,D0 */
- clrloop:
- clr.w -(SP)
- dbra D0,@clrloop
- move.l SP,A0
- move.w #-5,0x18(A0) /* #-5,ioRefNum(A0) */
- move.w drive_number,0x16(A0) /* #1,ioDrvNum(A0) internal drive */
- move.w #1,0x2C(A0) /* #1,ioPosMode(A0) absolute positioning */
- clr.l D0
- move.w sect_n,D0
- mulu #512,D0
- move.l D0,0x2E(A0) /* D0,ioPosOffset(A0) */
- move.l #512,0x24(A0) /* #512,ioReqCount(A0) /* read one sector */
- move.l buffer,A1
- move.l A1,0x20(A0) /* A1,ioBuffer(A0) */
- dc.w _Read
- move.w 0x10(A0),err_code /* ioResult(A0),err_code * /
- add.w #0x32,SP /* #ioQElSize,SP */
- }
- }
-
-
-
- scrivi_settore(sect_n,buffer)
- int sect_n;
- char *buffer;
- {
- #define _Write 0xA003
- asm{
- moveq #24,D0
- clrloop:
- clr.w -(SP)
- dbra D0,@clrloop
- move.l SP,A0
- move.w #-5,0x18(A0)
- move.w drive_number,0x16(A0)
- move.w #1,0x2C(A0)
- move.w sect_n,D0
- mulu #512,D0
- move.l D0,0x2E(A0)
- move.l #512,0x24(A0)
- move.l buffer,A1
- move.l A1,0x20(A0)
- dc.w _Write
- move.w 0x10(A0),err_code
- add.w #0x32,SP
- }
- }
-
-